package 双指针;

/**
 * @author tmh
 * @date 2024/9/9 21:31
 * @description
 */
public class T283移动零 {
    public void moveZeroes(int[] nums) {
        int left = 0;
        for (int right = 0; right < nums.length; right++) {
            if (nums[right] != 0) {
                nums[left] = nums[right];
                //如果right和left相同，就说明他们都指向的是一个不为0的数
                if (right != left) {
                    nums[right] = 0;
                }
                left++;
            }
        }
    }
}
